package com.victor9ac.mashup.elasticsearch.converter;

import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;

import java.io.IOException;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.common.xcontent.XContentBuilder;

import com.victor9ac.mashup.api.Comment;
import com.victor9ac.mashup.api.Commentaries;
import com.victor9ac.mashup.api.Image;
import com.victor9ac.mashup.api.Images;
import com.victor9ac.mashup.api.travel.Travel;
import com.victor9ac.mashup.api.travel.TravelRoute;

public class ElasticSearchTravelConverter implements ElasticSearchConverter {

	public Object convert(SearchResponse searchResponse) throws ParseException {
		// TODO Auto-generated method stub
		return null;
	}

	public List<XContentBuilder> buildJson(Object obj) throws IOException {
		Travel travel = (Travel) obj;

		List<XContentBuilder> contentList = new ArrayList<XContentBuilder>();
		
		for (TravelRoute route: travel.getTravelRoutes()){
		
			XContentBuilder json = jsonBuilder().startObject()
					.field("origin", travel.getFrom().toUpperCase())
					.field("destination", travel.getTo().toUpperCase())
			
					.field("routeName", route.getName())
					.field("routeDistance", route.getDistance())
					.field("routeDuration", route.getDuration())
					.field("routePrice", route.getPriceRoute())
					.field("dataDate", new Date())
					.endObject();
			
			contentList.add(json);
			
		}

		return contentList;
	}

}
